//
//  ReverseSingalLinkedList.c
//  LinkedList
//
//  Created by Xavier on 2023/10/10.
//

//反转单链表
//https://leetcode.cn/problems/reverse-linked-list/


#include <stdio.h>
struct ListNode {
     int val;
     struct ListNode *next;
 };
 
struct ListNode* reverseList(struct ListNode* head){
    if (head == NULL || head->next == NULL) {
        return NULL;
    }

    struct ListNode* res = NULL;
    struct ListNode* cur = head;
    while (cur) {
        struct ListNode* tmp = cur->next;
        cur->next = res;
        res = cur;
        cur = tmp;
    }
    return res;
}
